﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HdipCricketClub.ViewModels;

namespace HdipCricketClub.Models
{
    public partial class Result
    {
        public string ResultDescription
        {
            get
            {
                if (Fixture.ScorecardHeader.result_id == 1)
                {
                    return "No Result match called Off";
                }
                if (Fixture.ScorecardHeader.result_id == 2)
                {
                    return "No Result match abandoned";
                }
                if (Fixture.ScorecardHeader.result_id == 3)
                {
                    if (Fixture.ScorecardHeader.batted_first)
                    {
                        if (first_innings_runs > second_innings_runs)
                        {
                            return Fixture.Team.Club.ShortName + " won by " + (first_innings_runs - second_innings_runs) + " runs.";
                        }
                        if (second_innings_runs > first_innings_runs)
                        {
                            return Fixture.Opponent.club_name + " won by " + (10 - second_innings_wickets) + " wickets.";
                        }
                    }
                    else if (!Fixture.ScorecardHeader.batted_first)
                    {
                        if (first_innings_runs > second_innings_runs)
                        {
                            return Fixture.Opponent.club_name + " won by " + (first_innings_runs - second_innings_runs) + "runs.";
                        }
                        if (second_innings_runs > first_innings_runs)
                        {
                            return Fixture.Team.Club.ShortName + " won by " + (10 - second_innings_wickets) + " wickets.";
                        }
                    }
                }
                return "No Result";
            }
        }

        public string Validate(ScorecardResultTypeViewModel scorecardResultTypeViewModel)
        {
            string errorMessage = "";

            if ((scorecardResultTypeViewModel.ScorecardHeaderDetail.result_id != 1) && (scorecardResultTypeViewModel.ScorecardHeaderDetail.result_id != 2) && (scorecardResultTypeViewModel.ScorecardHeaderDetail.result_id != 3))
            {
                errorMessage = "You must enter how the match was completed";
            }

            return errorMessage;
        }
    }
}   
   
